<script>
import request from './api/request.js';
export default {
	async onLaunch(){
		let token = uni.getStorageSync('token');
		if (token) {
			let tokenTime = uni.getStorageSync('tokenTime');
			let time_difference = (new Date().getTime() - new Date(tokenTime).getTime()) / 1000 / 60 / 60 / 24;
			if (time_difference > 6 && time_difference < 8) {
				//在这个时间段内重新获取token,重新存储
				let res = await request({
					url: '/user/token', 
					data: {
						token: uni.getStorageSync('token')
					},
					method: 'POST'
				});
				uni.setStorageSync('token', res[1].data.token);
				uni.setStorageSync('tokenTime', new Date());
			} else if (time_difference > 7) {
				//token存储的时间大于7天，需要重新登录
				uni.removeStorageSync('token');
				uni.removeStorageSync('tokenTime');
				uni.navigateTo({
					url: 'pages/signin/signin'
				});
			} else {
				this.$store.dispatch('getNotice');
				this.$store.dispatch('getFriends');
				this.$store.dispatch('getAcquire');
				this.$store.dispatch('getUserInfo');
				this.$store.dispatch('getDyNotify');
				this.$store.dispatch('getComNotify');
				this.$store.dispatch('acquireVisitors');
				this.$store.dispatch('getDialogue');
				uni.switchTab({
					url: './pages/index/index'
				});
			}
		} else {
			uni.navigateTo({
				url: './pages/signin/signin'
			});
		}
	},
	onShow: function() {
		// console.log('App Show')
	},
	onHide: function() {
		// console.log('App Hide')
	}
};
</script>
<style>
/*每个页面公共css */
@import 'https://at.alicdn.com/t/font_1872738_qonhf418ypb.css';
</style>
